package com.zhengxin.one.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhengxin.one.common.Result;
import com.zhengxin.one.common.ResultPage;
import com.zhengxin.one.entity.Compensate;
import com.zhengxin.one.entity.entityClass.Page;
import com.zhengxin.one.service.impl.BillServiceipml;
import com.zhengxin.one.service.impl.CompensateServiceIpml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "shangshebao")
public class CompensateController {
    @Autowired
    private CompensateServiceIpml compensateServiceIpml;
    @Autowired
    private BillServiceipml billService;
    //社保理赔查询
    @RequestMapping(value = "comFound",method = RequestMethod.POST)
    public ResultPage comfund(@RequestParam int type,@RequestParam String keyword, @RequestParam String status, @RequestParam String company_id, @RequestParam int page, @RequestParam int size){
        List<Compensate> info = new LinkedList<>();
        PageHelper.startPage(page,size);
        info = compensateServiceIpml.penfind(type,company_id,status,keyword);
        PageInfo pageInfo = new PageInfo(info);
        Page pageinfos =new Page();
        pageinfos.setPageNum(pageInfo.getPageNum());
        pageinfos.setTotal((int)pageInfo.getTotal());
        return ResultPage.successp(info,pageinfos);
    }
    //社保理赔单个查询
    @RequestMapping(value = "comPerFound",method = RequestMethod.GET)
    public Result comperfund(@RequestParam String id_card){
        Map info = compensateServiceIpml.penperfind(id_card);
        return Result.success(info);
    }
    //社保理赔删除
    @RequestMapping(value = "comDele",method = RequestMethod.GET)
    public Result comdele(@RequestParam String id_card){
        String[] split=id_card.split(",");
        for (int i = 0; i < split.length; i++) {
            compensateServiceIpml.pendele(split[i]);
        }
        return Result.success("");
    }
    //社保理赔添加
    @RequestMapping(value = "comInsert",method = RequestMethod.POST)
    public Result cominsert(@RequestBody Compensate compensate){
        String id_card = compensate.getId_card();
        if(!billService.checkS(id_card)){
            return Result.fail("用户未添加社保");
        }
       if(compensateServiceIpml.penup(compensate)!=1){
           return Result.fail("操作失败");
       }
        return Result.success("");
    }
    //社保理赔修改
    @RequestMapping(value = "comUpdata",method = RequestMethod.POST)
    public Result comupdate(@RequestBody Compensate compensate){
        String id_card = compensate.getId_card();
        if(compensateServiceIpml.pendata(compensate)!=1){
            return Result.fail("操作失败");
        }
        return Result.success("");
    }
    //社保商保撤回
    @RequestMapping(value = "comBack",method = RequestMethod.GET)
    public Result comback(@RequestParam String id_card){
        if(compensateServiceIpml.penback(id_card)!=1){
            return Result.fail("操作失败");
        }
        return Result.success("");
    }
}
